<template>
  <div class="home">
    <!--整个页面的外层容器-->
    <el-container>
      <!--  顶栏    -->
      <el-header class="layout-header">
        <h1>酷鲨商城运营平台</h1>
      </el-header>
      <!-- 下半部分 -->
      <el-container class="layout-body">
        <!---侧边栏 -->
        <el-aside class="layout-aside" width="250px">
          <el-menu
              router
              :default-active="activeMenuItemPath"
              class="el-menu-vertical-demo"
              background-color="#2c3e50"
              text-color="#fff"
              active-text-color="#fff">
            <el-menu-item index="/sys-admin/index">
              <i class="el-icon-s-home"/>
              <span>首页</span>
            </el-menu-item>
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-menu"/>
                <span>临时页面</span>
              </template>
              <el-menu-item disabled index="/sys-admin/temp/admin/add-new">
                <i class="el-icon-circle-plus"/>
                <span>添加管理员</span>
              </el-menu-item>
              <el-menu-item disabled index="/sys-admin/temp/admin/list">
                <i class="el-icon-user"/>
                <span>管理员列表</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/album/add-new">
                <i class="el-icon-circle-plus"/>
                <span>添加相册</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/album/list">
                <i class="el-icon-picture-outline-round"/>
                <span>相册列表</span>
              </el-menu-item>
              <el-menu-item disabled index="/sys-admin/temp/category/add-new">
                <i class="el-icon-circle-plus"/>
                <span>添加类别</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/category/category-by-list">
                <i class="el-icon-s-operation"/>
                <span>类别列表</span>
              </el-menu-item>
              <el-menu-item disabled index="/sys-admin/temp/brand/add-new">
                <i class="el-icon-circle-plus"/>
                <span>添加品牌</span>
              </el-menu-item>
              <el-menu-item disabled>
                <i class="el-icon-medal"/>
                <span>品牌列表</span>
              </el-menu-item>
            </el-submenu>
            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-menu"/>
                <span>商品管理</span>
              </template>
              <el-menu-item index="3-1">
                <i class="el-icon-menu"/>
                <span>SPU台账</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/spu/add-new-1">
                <i class="el-icon-menu"/>
                <span>新增SPU</span>
              </el-menu-item>
            </el-submenu>
            <el-submenu disabled index="4">
              <template slot="title">
                <i class="el-icon-menu"/>
                <span>订单管理</span>
              </template>
            </el-submenu>
            <el-submenu disabled index="5">
              <template slot="title">
                <i class="el-icon-menu"/>
                <span>营销管理</span>
              </template>
            </el-submenu>
            <el-submenu disabled index="6">
              <template slot="title">
                <i class="el-icon-menu"/>
                <span>商家管理</span>
              </template>
            </el-submenu>
            <el-submenu disabled index="7">
              <template slot="title">
                <i class="el-icon-menu"/>
                <span>权限管理</span>
              </template>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!--主栏--->
        <!-- el-main 是一个布局组件，用于定义页面的主要内容区域 -->
        <el-main class="layout-main">
          <!-- router-view 是 Vue Router 提供的组件，用于渲染当前路由对应的组件 -->
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style>
/* 设置头部样式 */
.layout-header h1 {
  color: #fff;
  line-height: 60px;
  font-family: 楷体, serif;
}

/* 设置头部背景颜色 */
.layout-header {
  background: dodgerblue;
}

/* 设置主体样式 */
.layout-body {
  position: absolute;
  top: 60px;
  bottom: 0;
  left: 0;
  right: 0;
}

/* 设置侧边栏样式 */
.layout-aside {
  background: #2c3e50;
}

/* 设置主内容区样式 */
.layout-main {
  background: #e9eef3;
}

/* 设置图标颜色为白色，!important表示优先级最高 */
.layout-aside i {
  color: #fff !important;
}

.el-menu-item.is-active {
  background: #222c32 !important;
}
</style>
<script>
export default {
  data() {
    return {
      activeMenuItemPath: ''
    }
  },
  created() {
    let jwt = localStorage.getItem('jwt');
    if (!jwt) {
      this.$router.push('/sys-admin/login');
    }
  },
  mounted() {
    let path = this.$router.currentRoute.path;
    if (path.startsWith('/sys-admin/product/spu/add-new-')) {
      this.activeMenuItemPath = '/sys-admin/product/spu/add-new-1';
    } else {
      this.activeMenuItemPath = path;
    }
  }
}
</script>